<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglib.jsp"%>
<!doctype html>
<html class="x-border-box x-strict x-viewport">
<head>
<%@ include file="/common/head-system.jsp"%>
<title>录入</title>
<script type="text/javascript">
	window.refreshQuery = function() {
		location.reload();
	};
	jQuery(function() {
	});
	function add2mapping(){
		var f = jQuery("#mainForm");
		f.attr("action", "addTable2mapping.do");
		f.submit();
	}
	function saveMapping(){
		var f = jQuery("#mainForm");
		f.attr("action", "save.do");
		f.submit();
	}
	function refreshTables(){
		var f = jQuery("#mainForm");
		f.attr("action", "input.do");
		f.submit();
	}
	function generate(){
		var f = jQuery("#mainForm");
		f.attr("action", "generate.do");
		f.submit();
	}
	function deleteEntities(){
		var f = jQuery("#mainForm");
		f.attr("action", "generate!deleteEntities.do");
		f.submit();
	}
	function selectAll(checkbox, classSuffix){
		jQuery(".select-all-"+classSuffix).attr("checked", checkbox.checked);
	}
</script>
</head>
<body class="x-body x-reset x-border-layout-ct x-container">
	<form action="input.do" method="post" id="mainForm">
		<s:token />
		<s:hidden name="id" />
		<ext:panel head="录入">
			<ext:formField labelname="路径" fieldname="nameText">
				<s:textfield name="nameText" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="表前缀" fieldname="prefixText">
				<s:textfield name="prefixText" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="JDBC驱动" fieldname="jdbcDriver">
				<s:textfield name="jdbcDriver" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="JDBC链接" fieldname="jdbcUrl">
				<s:textfield name="jdbcUrl" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="JDBC用户名" fieldname="jdbcUsername">
				<s:textfield name="jdbcUsername" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="JDBC密码" fieldname="jdbcPassword">
				<s:textfield name="jdbcPassword" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="JNDI" fieldname="jndiText">
				<s:textfield name="jndiText" cssClass="x-form-field x-form-text"
					cssStyle="width: 100%;" />
			</ext:formField>
		</ext:panel>
		<br />
		<ext:panel head="当前数据库所有表">
			<table>
				<tr>
					<td><ext:formField labelname="表名"
							fieldname="tableQuery.tableName">
							<s:textfield name="tableQuery.tableName"
								cssClass="x-form-field x-form-text" cssStyle="width: 100%;" />
						</ext:formField></td>
					<td><ext:formField labelname="备注"
							fieldname="tableQuery.comments">
							<s:textfield name="tableQuery.comments"
								cssClass="x-form-field x-form-text" cssStyle="width: 100%;" />
						</ext:formField></td>
				</tr>
			</table>
			<div class="my-grid">
			<table cellpadding="0" border="0" cellspace="0" width="100%">
				<tr>
					<td width="30"><ext:gridHeadCell>
							序号
						</ext:gridHeadCell>
					</td>
					<td width="50"><ext:gridHeadCell align="center">
							<input type="checkbox" onclick="selectAll(this, 'tableNames')" />选择
						</ext:gridHeadCell></td>
					<td><ext:gridHeadCell>
							名称
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell name="tableName" page="tables"
							sortable="true">
							表名
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							备注
						</ext:gridHeadCell>
					</td>
					<td width="50"><ext:gridHeadCell align="center">
							操作
						</ext:gridHeadCell>
					</td>
				</tr>
				<s:iterator value="tables.result" id="vo" status="s">
					<s:if test="#s.count%2 == 1">
						<s:set name="rc" value="''" />
					</s:if>
					<s:else>
						<s:set name="rc" value="' x-grid-row-alt'" />
					</s:else>
					<tr class="x-grid-row<s:property value='rc' />">
						<td style="padding-left: 0px;"
							class=" x-grid-cell x-grid-cell-special x-grid-cell-first"><div
								style="text-align: right; font-weight: bolder;"
								class="x-grid-cell-inner">
								<s:property value="#s.count" />
							</div></td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<input type="checkbox" name="tableNames"
									class="select-all-tableNames"
									value="<s:property value='#vo.tableName'/>" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left; width: 150px;"
								class="x-grid-cell-inner">
								<span class="show-title"><s:property value="#vo.nameShow" />
								</span>
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.tableName" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left; width: 150px;"
								class="x-grid-cell-inner">
								<s:property
										value="#vo.commentText" />
							</div>
						</td>
						<td class=" x-grid-cell x-grid-cell-last"><div
								 style="text-align: left;" class="x-grid-cell-inner">
								<s:url id="u"
									value='%{"/mapping/" + mapping.nameText + "/tables/" + #vo.nameText + "/list.do"}' includeParams="none" />
								<s:a href="%{u}">
								数据
								</s:a>
							</div>
						</td>
					</tr>
				</s:iterator>
			</table>
			</div>
			<ext:page page="tables" />
			<ext:formField labelname="包路径" fieldname="defaultEntity.packageText">
				<s:textfield name="defaultEntity.packageText"
					cssClass="x-form-field x-form-text" cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="是否有表前缀" fieldname="defaultEntity.hasPrefix">
				<s:radio name="defaultEntity.hasPrefix" list="#application.M.getDictByType('yn')" listKey="code" listValue="name" />
			</ext:formField>
			<ext:formField labelname="表前缀" fieldname="defaultEntity.prefixText">
				<s:textfield name="defaultEntity.prefixText"
					cssClass="x-form-field x-form-text" cssStyle="width: 100%;" />
			</ext:formField>
			<ext:formField labelname="是否有效" fieldname="defaultEntity.isWork">
				<s:radio name="defaultEntity.isWork" list="#application.M.getDictByType('yn')" listKey="code" listValue="name" />
			</ext:formField>
			<div
				style="width: 100%; height: 34px; text-align: right; padding: 3px 0px;">
				<ext:button name="加入集合" width="80" onclick="add2mapping();" />
			</div>
		</ext:panel>
		<br />
		<ext:panel head="实体列表">
			<div class="my-grid">
			<table cellpadding="0" border="0" cellspace="0" width="100%">
				<tr>
					<td width="30"><ext:gridHeadCell>
							序号
						</ext:gridHeadCell>
					</td>
					<td width="50"><ext:gridHeadCell align="center">
							<input type="checkbox" onclick="selectAll(this, 'ids')" />选择
						</ext:gridHeadCell></td>
					<td><ext:gridHeadCell>
							主键
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							包路径
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							是否有表前缀
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							表前缀
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							名称
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							显示名称
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							表名
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							备注
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							是否有效
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							是否<br>隶属于集合
						</ext:gridHeadCell>
					</td>
					<td><ext:gridHeadCell>
							父元素
						</ext:gridHeadCell>
					</td>
					<td width="50"><ext:gridHeadCell align="center">
							操作
						</ext:gridHeadCell>
					</td>
				</tr>
				<s:iterator value="entities.result" id="vo" status="s">
					<s:if test="#s.count%2 == 1">
						<s:set name="rc" value="''" />
					</s:if>
					<s:else>
						<s:set name="rc" value="' x-grid-row-alt'" />
					</s:else>
					<tr class="x-grid-row<s:property value='rc' />">
						<td style="padding-left: 0px;"
							class=" x-grid-cell x-grid-cell-special x-grid-cell-first"><div
								style="text-align: right; font-weight: bolder;"
								class="x-grid-cell-inner">
								<s:property value="#s.count" />
							</div></td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<input type="checkbox" name="ids"
									class="select-all-ids"
									value="<s:property value='#vo.id'/>" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.id" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.packageText" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#application.M.getDictNameByTypeAndCode(#vo.hasPrefix, 'yn')" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.prefixText" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.nameText" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.nameShow" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.tableName" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.commentText" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#application.M.getDictNameByTypeAndCode(#vo.isWork, 'yn')" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#application.M.getDictNameByTypeAndCode(#vo.isParentMapping, 'yn')" />
							</div>
						</td>
						<td class=" x-grid-cell"><div style="text-align: left;"
								class="x-grid-cell-inner">
								<s:property value="#vo.parentId" />
							</div>
						</td>
						<td class=" x-grid-cell x-grid-cell-last"><div
								 style="text-align: left;" class="x-grid-cell-inner">
								<s:url id="u"
									value="%{'/mapping/' + model.nameText + '/' + nameText + '/list.do'}" includeParams="none" />
								<ext:button name="数据" onclick='%{"window.open(\'" + #u +"\')"}' />
								<s:url id="u" action="../entity/input" includeParams="none">
									<s:param name="id">
										<s:property value="#vo.id" />
									</s:param>
								</s:url>
								<ext:button name="修改" onclick='%{"window.open(\'" + #u +"\')"}' />
								<s:url id="u" action="../entity/input!delete" includeParams="none">
									<s:param name="id">
										<s:property value="#vo.id" />
									</s:param>
								</s:url> 
								<ext:button name="删除" onclick='%{"jQuery.hiddenRequest(\'" + #u +"\')"}' />
							</div>
						</td>
					</tr>
				</s:iterator>
			</table>
			</div>
			<ext:page page="entities" />
			<div
				style="width: 100%; height: 34px; text-align: right; padding: 3px 0px;">
				<ext:button name="删除实体" width="70" onclick="deleteEntities();" />
			</div>
		</ext:panel>
		<br/>
		<ext:panel head="其它选项">
			<ext:formField fieldname="types" labelname="生成类型" fieldwidth="300">
				<input type="checkbox" name="generatedTypes" value="1" />SQL
							<input type="checkbox" name="generatedTypes" value="2" />HBM
							<input type="checkbox" name="generatedTypes" value="3" />Entity
							<input type="checkbox" name="generatedTypes" value="4" />Mapper
							<input type="checkbox" name="generatedTypes" value="5" />ListVo
			</ext:formField>
			<div
				style="width: 100%; height: 34px; text-align: right; padding: 3px 0px;">
				<ext:button name="生成代码" width="70" onclick="generate();" />
			</div>
		</ext:panel>
		<br/>
		<div
			style="width: 100%; height: 34px; text-align: center; padding: 3px 0px;">
			<ext:button name="保存集合" width="70" onclick="saveMapping();" />
		</div>
	</form>
	<%@ include file="/common/foot.jsp"%>
</body>
</html>